#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:进程之间不共享全局变量.py
# author: 马国鑫
# datetime:2022/3/26 21:02
# software: PyCharm

"""
this is function  description 
"""
import multiprocessing
import time

# 全局变量列表
g_num = []


def my_write():
    """
    想全局变量写入数据
    :return:
    """
    global g_num
    for i in range(5):
        g_num.append(i)
    print("my_write:",g_num)



def my_read():
    """读取全局变量g_num的值"""
    global g_num
    print("my_read:",g_num)


if __name__ == '__main__':
    # 创建子进程
    # target放入自己选择的函数
    test_write = multiprocessing.Process(target=my_write)
    test_read = multiprocessing.Process(target=my_read)
    # 开启线程
    test_write.start()
    time.sleep(1)
    # 保证数据写入g_num
    test_read.start()
    # print(g_num)
